package top.scsoul.pas.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import top.scsoul.pas.entity.Clazz;

import java.util.List;

@Repository
public interface ClazzRepository extends JpaRepository<Clazz, Long> {
    boolean existsByName(String name);

    /**
     * 判断班级是否存在 返回条数
     * @param clazzName
     * @return
     */
    @Query(value = "select count(clazz.clazz_id) from clazz where clazz.clazz_name = ?1", nativeQuery = true)
    long getCountByClazzName(String clazzName);

    /**
     * 通过班主任id查询该班主任的班级
     * @param leaderId
     * @return
     */
    @Query(value = "select * from clazz where clazz.clazz_leader=?1", nativeQuery = true)
    List<Clazz> getAllClazzByLeaderId(Long leaderId);
}
